﻿using Project.Core.Config.Entity;
using Project.Core.Config.Entity.Dto;
using Project.Core.Config.Mapper;

namespace Project.Core.Config.Service.Impl {
    public class ServiceImpl<M, T, L> : IService<T, L> where T : BaseEntity<L> where M : BaseMapper<T, L>
    {

        public M BaseMapper { get; set; }

        public List<T> GetAll() {
            return BaseMapper.GetAll().ToList();
        }
        public async Task<List<T>> GetAllAsync() {
            return await BaseMapper.GetAllAsync();
        }
        public Page GetAll(Page page) {
            return BaseMapper.GetAll(page);
        }

        public T GetById(L id) {
            return BaseMapper.GetById(id);
        }
        public async Task<T> GetByIdAsync(L id) {
            return await BaseMapper.GetByIdAsync(id);
        }
        public List<T> ListByIds(IEnumerable<L> idList) {
            return BaseMapper.GetByIds(idList).ToList();
        }
        public async Task<List<T>> ListByIdsAsync(IEnumerable<L> idList) {
            return await BaseMapper.GetByIdsAsync(idList);
        }

        public T Add(T data) {
            return BaseMapper.Add(data);
        }
        public async Task<T> AddAsync(T data) {
            return await BaseMapper.AddAsync(data);
        }
        public List<T> AddList(IEnumerable<T> dataList) {
            return BaseMapper.AddBatch(dataList).ToList();
        }
        public async Task<List<T>> AddListAsync(IEnumerable<T> dataList) {
            return await BaseMapper.AddBatchAsync(dataList);
        }

        public T Delete(T data) {
            return BaseMapper.Delete(data);
        }
        public async Task<T> DeleteAsync(T data) {
            return await BaseMapper.DeleteAsync(data);
        }
        public T DeleteById(L id) {
            return BaseMapper.DeleteById(id);
        }
        public async Task<T> DeleteByIdAsync(L id) {
            return await BaseMapper.DeleteByIdAsync(id);
        }
        public List<T> DeleteList(IEnumerable<T> dataList) {
            return BaseMapper.DeleteBatch(dataList).ToList();
        }
        public async Task<List<T>> DeleteBatchAsync(IEnumerable<T> dataList) {
            return await BaseMapper.DeleteBatchAsync(dataList);
        }
        public List<T> DeleteByIds(IEnumerable<L> idList) {
            return BaseMapper.DeleteBatchIds(idList).ToList();
        }
        public async Task<List<T>> DeleteBatchIdsAsync(IEnumerable<L> idList) {
            return await BaseMapper.DeleteBatchIdsAsync(idList);
        }

        public T Update(T updateData) {
            return BaseMapper.Update(updateData);
        }
        public async Task<T> UpdateAsync(T updateData) {
            return await BaseMapper.UpdateAsync(updateData);
        }
        public List<T> UpdateList(IEnumerable<T> updateData) {
            return BaseMapper.UpdateBatch(updateData).ToList();
        }
        public async Task<List<T>> UpdateListAsync(IEnumerable<T> updateData) {
            return await BaseMapper.UpdateBatchAsync(updateData);
        }

        public Page<T> Page(Page page) {
            return BaseMapper.Page(page);
        }

        public Page<E> Page<E>(Page page, IEnumerable<E> list) {
            return BaseMapper.Page(page, list);
        }
    }
}
